home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / kbd.lzh / KBD.C next >
C/C++ Source or Header  |  1990-06-17  |  2KB  |  162 lines

  1. /*
  2.  * Set keyboard click/bell
  3.  *
  4.  * Dave Baggett
  5.  *
  6.  * Compiled with Sozobon C.  Your mileage may vary.
  7.  */
  8. #include <stdio.h>
  9. #include <osbind.h>
  10.  
  11. #define CONTERM *((unsigned char *) 0x484)
  12.  
  13. int    cs, bs, rs;
  14.  
  15. static void    c_off(), c_on(), b_off(), b_on(), r_off(), r_on(), usage();
  16. static void    c_status(), b_status(), r_status();
  17.  
  18. main(argc, argv)
  19.     int    argc;
  20.     char    **argv;
  21. {    
  22.     register int        i;
  23.     register unsigned char    id, rd;
  24.     
  25.     if (argc < 2) {
  26.         usage();
  27.         exit(0);
  28.     }
  29.  
  30.     for (i = 1; i < argc; i++) {
  31.         switch (argv[i][1]) {
  32.             case 'c':
  33.             case 'C':
  34.                 if (argv[i][0] == '-')
  35.                     Supexec(c_off);
  36.                 else
  37.                     Supexec(c_on);    
  38.                 break;
  39.             case 'b':
  40.             case 'B':
  41.                 if (argv[i][0] == '-')
  42.                     Supexec(b_off);
  43.                 else
  44.                     Supexec(b_on);    
  45.                 break;
  46.             case 'r':
  47.             case 'R':
  48.                 if (argv[i][0] == '-')
  49.                     Supexec(r_off);
  50.                 else {
  51.                     Supexec(r_on);    
  52.                     
  53.                     if (i + 2 < argc) {
  54.                         id = atoi(argv[++i]);
  55.                         rd = atoi(argv[++i]);
  56.                     
  57.                         Kbrate(id, rd);
  58.                     }
  59.                 }
  60.                 break;
  61.  
  62.             default:
  63.                 usage();
  64.                 exit(-1);
  65.                 break;
  66.         }
  67.     }
  68.  
  69.     exit(0);
  70. }
  71.  
  72. static void
  73. usage()
  74. {
  75.     unsigned int    repeat;
  76.     unsigned char    id, rd;
  77.     static char    str[80];
  78.     static char    onoff[2][10] = {"[off]", "[on]"};
  79.  
  80.     /*
  81.      * Get current values
  82.      */
  83.     Supexec(c_status);
  84.     Supexec(b_status);
  85.     Supexec(r_status);
  86.  
  87.     repeat = Kbrate(-1, -1);
  88.     repeat &= 0x0000FFFF;
  89.     id = repeat >> 8;
  90.     rd = repeat &= 0x00FF;
  91.  
  92.     Cconws("usage: kbd {-c|-b|-r} {+c|+b|+r [id rd]}\r\n");
  93.     Cconws("c = click, b = bell, r = repeat\r\n");
  94.     Cconws("id = initial delay, rd = repeat delay\r\n");
  95.     Cconws("Delays are in ticks (~20 microseconds)\r\n");
  96.     Cconws("\r\nCurrent values:\r\n");
  97.     sprintf(str, "click: %s   bell: %s   repeat: %s\r\n", 
  98.         onoff[cs], onoff[bs], onoff[rs]);
  99.     Cconws(str);
  100.  
  101.     if (rs) {
  102.         sprintf(str, "initial delay = %d   repeat delay = %d\r\n",
  103.             id, rd);
  104.         Cconws(str);
  105.     }
  106. }
  107.  
  108. static void
  109. c_off()
  110. {
  111.     CONTERM &= 0xFE;
  112. }
  113.  
  114. static void
  115. c_on()
  116. {
  117.     CONTERM |= 0x01;
  118. }
  119.  
  120. static void
  121. c_status()
  122. {
  123.     cs = (CONTERM & 0x01) ? 1 : 0;
  124. }
  125.  
  126. static void
  127. b_off()
  128. {
  129.     CONTERM &= 0xFB;
  130. }
  131.  
  132. static void
  133. b_on()
  134. {
  135.     CONTERM |= 0x04;
  136. }
  137.  
  138. static void
  139. b_status()
  140. {
  141.     bs = (CONTERM & 0x04) ? 1 : 0;
  142. }
  143.  
  144. static void
  145. r_off()
  146. {
  147.     CONTERM &= 0xFD;
  148. }
  149.  
  150. static void
  151. r_on()
  152. {
  153.     CONTERM |= 0x02;
  154. }
  155.  
  156. static void
  157. r_status()
  158. {
  159.     rs = (CONTERM & 0x02) ? 1 : 0;
  160. }
  161.  
  162.